import { createApp } from 'vue';
// import { createPinia } from 'pinia'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import appStorage from './stores/storage';
import { StorageKey } from './constant';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';//导入所有element icon图标

const app = createApp(App)
//全局功能权限校验,通过v-permission="'user:add'"或v-permission:disabled="'user:add'"
app.directive('permission', {
  mounted(el, binding) {
    const code = binding.value;
    const arg = binding.arg;
    let permissions = appStorage.getSession(StorageKey.PERMISSION_OPERATOR);
    let result = permissions.find(item => item.permissionCode == code)
    if (result == null) {
      // console.log('nopermission')
      if (arg != null && arg == 'disabled') {
        //禁用
        el.disabled = true;
        el.classList.add('is-disabled');
      }
      else {
        el.parentNode.removeChild(el);//移除
      }
    }
  }
});

app.use(router)

//动态菜单图标需要提前注册
const icons = ['HomeFilled', 'Setting', 'User']
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  if (icons.includes(key)) {
    app.component(key, component)
  }
}

app.mount('#app')
